export default{
	data(){
		return{
			diyData: {
				global: {
					title: '',
					popWindow: {
						imageUrl: '',
						count: -1,
						link: {},
						imgWidth: '',
						imgHeight: ''
					}
				}
			},
		}
	},
	onShow(){
		this.getDiyInfo()
	},
	methods:{
		getDiyInfo(isRefresh) {
			this.$api.sendRequest({
				url: '/api/diyview/info',
				data: {
					name: this.name,
					is_default: this.isDefault
				},
				success: res => {
					if (res.code != 0 || !res.data) {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
						this.diyData = {};
						return;
					}

					let diyDatavalue = res.data;
					//处理后台组件input输入单引号问题 -- 英文状态下
					// diyDatavalue.value = diyDatavalue.value.replace(/\@/g, "'");
					if (diyDatavalue.value) {
						this.diyData = JSON.parse(diyDatavalue.value);
		
						if (this.name == 'DIY_VIEW_INDEX' && this.siteInfo) {
							this.diyData.global.title = this.siteInfo.site_name;
						} else {
							this.$langConfig.title(this.diyData.global.title);
						}
						this.mpCollect = this.diyData.global.mpCollect;
						if (this.diyData.global.popWindow && this.diyData.global.popWindow.imageUrl) {
							// 弹框形式，首次弹出 1，每次弹出 0
							setTimeout(() => {
								if (this.diyData.global.popWindow.count == 1) {
									var popwindow_count = uni.getStorageSync(this.name +
										'_popwindow_count');
									if ((this.$refs.uniPopupWindow && popwindow_count == '') || (
											this.$refs.uniPopupWindow && popwindow_count == 1)) {
										this.$refs.uniPopupWindow.open();
										uni.setStorageSync(this.name + '_popwindow_count', 1);
									}
								} else if (this.diyData.global.popWindow.count == 0) {
									this.$refs.uniPopupWindow.open();
									uni.setStorageSync(this.name + '_popwindow_count', 0);
								}
							}, 500);
						}
		
						for (var i = 0; i < this.diyData.value.length; i++) {
							if (this.diyData.value[i].componentName == 'TopCategory') {
								this.topIndexValue = this.diyData.value[i];
								break;
							}
						}
					}
					setTimeout(() => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}, 150);
				}
			});
		},
	}
}